package study.stream.reduce;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

/**
 * @Author 金贵权
 * @Date 2023/6/12 17:01
 **/
public class ReduceDemo {
    public static void main(String[] args) {
        List<Integer> integers = new ArrayList<>();
        Integer reduce = integers.stream().reduce(0, Integer::sum);
        System.out.println(reduce);

        Optional<Integer> reduce2 = integers.stream().reduce(Integer::sum);
        System.out.println(reduce2);
        System.out.println(reduce2.orElse(0));


        Optional<Integer> reduce1 = integers.stream().reduce((a, b) -> (a + b));
        System.out.println(reduce1);
        reduce1.ifPresent(System.out::println);

        int a=2,b=3;
        Optional<Integer> max = integers.stream().reduce(Integer::max);
        System.out.println(max);

        getValue(System.out::println);

    }
    static String a = "10";
    public static void getValue(Consumer<String> consumer){
        consumer.accept(a);
    }
}
